package org.example.design.chain.service;

import org.example.design.chain.bean.AuthInfo;

import java.text.ParseException;
import java.util.Date;

/**
 * @Classname Level3AuthLink
 * @Description TODO
 * @Date 2020/11/6 11:30 上午
 * @Created by xiangjd
 */
public class Level3AuthLink extends AuthLink{

    private Date beginDate = f.parse("2020-11-01 00:00:00");
    private Date endDate = f.parse("2020-11-25 23:59:59");
    public Level3AuthLink(String levelUserId, String levelUsername) throws ParseException {
        super(levelUserId, levelUsername);
    }

    @Override
    public AuthInfo doAuth(String uid, String orderId, Date authDate) {
        Date date = AuthService.queryAuthInfo(levelUserId, orderId);
        if (null == date) {
            return new AuthInfo("0001", "单号：", orderId, " 状态：待三级审批负责人 ", levelUsername);
        }
        AuthLink next = super.next();
        if (null == next) {
            return new AuthInfo("0000", "单号：", orderId, " 状态：三级审批负责人完成", " 时间：", f.format(date), " 审批人：", levelUsername);
        }

        if (authDate.before(beginDate) || authDate.after(endDate)) {
            return new AuthInfo("0000", "单号：", orderId, " 状态：三级审批负责人完成", " 时间：", f.format(date), " 审批人：", levelUsername);
        }

        return next.doAuth(uid, orderId, authDate);
    }
}
